var map;
var oTable1;

		//获取所有湿地信息
		$.ajax({
			url:'../indicator/getallwetlandinfonew',
			async:true,
			type:'POST',
			success:function(data){
				var prov_info;
				var city_info;
				var dist_info;
				var length=data.length;
				 
				//联动下拉框初始化为江苏
				var provinceName=localStorage.provinceName;
				$('#addprov').val(provinceName);
				$('#addprov').trigger('change');
				$('#province').val(provinceName);
				$('#province').trigger('change');
				$('#select').empty();	
				$('#select').append(' <option value="">请选择保护主体</option>');							
				prov_info=$('#province').val();																	
				for(var i=0;i<length;i++){
					if(data[i].province==prov_info)$('#select').append('<option value='+data[i].name+'_'+i+'>'+data[i].name+'</option>');																	
				}  
				
				//该账号只存在一个湿地公园
				if(data.length==1){
					$('#select').val(data[0].name+"_0");							
					var arr=$("#select").val().match(/\d\d\d\d|\d\d\d|\d\d|\d/g);	
					var num=arr[arr.length-1];								
					//改变市和区					
					$("#city .city").children("option").each(function(){ 	
						
			              if( $(this).val()== data[num].city){  
			                    $('.city').val(data[num].city);  
			              }  
						
			         }); 																									
					$('#city .city').trigger("change");
					$("#city .dist").children("option").each(function(){ 									
			              if( $(this).val()== data[num].district){  
			                    $('#city .dist').val(data[num].district);  
			              }  
						
			         }); 
					//湿地公园改变后搜索框随之改变
					var valarr=$("#select").val().split('_');
					$('#search').val(data[0].name);
					var wetland_val=data[0].name;	 					
					//湿地公园表格涮选
					$('#sample-table-2').DataTable().column(0).search(wetland_val).draw();
					
				}
				
				//选择省后确定湿地公园
				$('#province').change(function(){
					$('#select').empty();	
					$('#select').append(' <option value="">请选择保护主体</option>');	
					$('#search').val("");
					prov_info=$(this).val();	
						var $city=$('#selectcity option');						
						for(var i=0;i<length;i++){
							if(data[i].province==$(this).val()){
								$('#select').append('<option value='+data[i].name+'_'+i+'>'+data[i].name+'</option>');																	
							}else if(prov_info==''){
								$('#select').append('<option value='+data[i].name+'_'+i+'>'+data[i].name+'</option>');
							}
						}	

						$('#sample-table-2').DataTable().ajax.reload().column(3).search(prov_info).draw(); 
						confirm();
						
					
					
				});	
				//改变湿地公园市和区随之改变
				$('#select').change(function(){
					//if($(this).val()=='')return;	
					
					if($(this).val()!=""){
						var arr=$(this).val().match(/\d\d\d\d|\d\d\d|\d\d|\d/g);	
						var num=arr[arr.length-1];						
					//改变市和区					
					$("#selectcity").children("option").each(function(){ 	
			              if( $(this).val()== data[num].city){  
			                    $('#selectcity').val(data[num].city);  
			              }  
			         }); 																									
					$('#selectcity').trigger("change");
					$("#selectdist").children("option").each(function(){ 									
			              if( $(this).val()== data[num].district){  
			                    $('#selectdist').val(data[num].district);  
			              }  
			         }); 
					//湿地公园改变后搜索框随之改变
					var valarr=$(this).val().split('_');
					$('#search').val(valarr[0]);

					//showPie();
					$('#sample-table-2').DataTable().ajax.reload().column(0).search(valarr[0]).draw(); 
					confirm();
					selectwetland();
					}
					else{
						$('#selectcity').val("");
						$('#selectcity').trigger("change");
						$('#search').val("");

						//showPie();
						$('#sample-table-2').DataTable().ajax.reload().column(0).search("").draw(); 
						confirm();
					}				
				});
				
				//改变市联动				
				$('#selectcity').click(function(){	
					$('#search').val("");
					city_info=$(this).val();
					if($(this).val()==''){
						$('#select').empty();	
						$('#select').append(' <option value="">请选择保护主体</option>');							
						prov_info=$('#province').val();	
						$('#search').val("");
						console.log(prov_info);										
						for(var i=0;i<length;i++){
							if(data[i].province==prov_info)$('#select').append('<option value='+data[i].name+'_'+i+'>'+data[i].name+'</option>');																	
						}
						
						
					}else{
						$('#select').empty();
						$('#select').append(' <option value="">请选择保护主体</option>');							
						for(var i=0;i<length;i++){								
							if(data[i].city==$(this).val()&&data[i].province==prov_info){
								$('#select').append('<option value='+data[i].name+'_'+i+'>'+data[i].name+'</option>');																		
							}									
						}	
					}	
		
					//showPie();
					//oTable1.column(2).search(city_info).draw();
					$('#sample-table-2').DataTable().ajax.reload().column(3).search(city_info).draw();
					confirm();
					
				});
				//改变区联动
				$('#selectdist').click(function(){    
					dist_info=$(this).val();
					city_info=$('#selectcity').val();
					if($(this).val()==''){
						$('#search').val('');
						$('#city #selectcity').trigger('click');
						$('#sample-table-2').DataTable().ajax.reload().column(3).search(city_info).draw();
						confirm();
						
					}else{
						
						$('#select').empty();	
						$('#select').append(' <option value="">请选择保护主体</option>');		
						//$('#search').val(dist_info);
						for(var i=0;i<length;i++){
							if(data[i].district==$(this).val()&&data[i].province==prov_info)$('#select').append('<option value='+data[i].name+'_'+i+'>'+data[i].name+'</option>');																	
						}
						$('#sample-table-2').DataTable().ajax.reload().column(3).search(dist_info).draw();
						confirm();
					}
					
				}); 
				
				
				
				
				
				//湿地类型涮选
				$('#search_system').change(function(){
					var val=$(this).val();

					$('#sample-table-2').DataTable().ajax.reload().column(1).search(val).draw(); 
					confirm();
					
				});

				$('#search_form').change(function(){
					var val=$(this).val();

					$('#sample-table-2').DataTable().ajax.reload().column(2).search(val).draw(); 
					confirm();
					
				});
				
				
				
				
				//搜索关联湿地公园
				var arr=[];
				var arr2=[];
				for(var i=0;i<length;i++){
					arr.push(data[i].name);
					arr2.push(data[i].name+'_'+i);
				}
				
				$('#search').autocomplete({
						lookup:arr,
						onSelect:function(){							
							var val=$(this).val();								
							for(var i=0;i<arr2.length;i++){								
								if(arr2[i].match(val)){
									var num=arr2[i].match(/\d/g)[0];									
									$('#province').val(data[num].province); 
									$('#province').trigger("change");																						
								    $("#select option").each(function(){  //遍历所有option  
								          var txt = $(this).val();  
								          if(txt.match(val))$(this).attr('selected','selected');									              
								     }) ;
									$('#select').trigger("change");
									$('#selectdist').trigger("click");
									  $("#select option").each(function(){  //遍历所有option  
								          var txt = $(this).val();  
								          if(txt.match(val))$(this).attr('selected','selected');
								     }) ;
								}
							}
							selectwetland();
							
						},
					});		
			},
			error:function(e){
				console.log(e);

				  new $.zui.Messager('服务器报错，请联系相关人员。', {
				        icon: 'bell' // 定义消息图标
				    }).show();
			}
		});  
			

$(function() {
	var url=window.location.pathname.split('/web')[1]
	var authorityArr=authorityMap[url];				//增删查改		
	$('#addWetland').attr('disabled',!Boolean(authorityArr[0]));
	
	//gis地图
/*	$.ajax({
		url : "../wetlandManager/findtotalmapserver",
		dataType : "json",
		type : "POST",
		data : {},
		async : true,
		error : function(error) {
			console.log(error.responseText);

			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell' // 定义消息图标
			    }).show();

		},
		success : function(strValue) {
			if (strValue != null) {

				$("#add_gismapserver").empty();
				$("#add_gismapserver").append("<option value=' '>请选择GIS图层</option>");
				for ( var i in strValue) {
					var option = "<option value=" + strValue[i] + ">"
							+ strValue[i] + "</option>";
					$("#add_gismapserver").append(option);
				}

			}
		}
	});
	*/

	
	var view=true;
	var delete1=true;
	var update=true;
	if($('#view').length>0){
		view=true;
	}else{
		view=false;
	}
	if($('#delete1').length>0){
		delete1=true;
	}else{
		delete1=false;
	}
	if($('#update').length>0){
		update=true;
	}else{
		update=false;
	}

	oTable1 = $('#sample-table-2').DataTable({
		'sAjaxSource': '../wetlandManager/alldatatablenew', 
		"bSort" : true,
		"pagingType": "full_numbers",
		"scrollCollapse": false,
		//汉化
		"scrollY": "600px", 
		"language": {
             "lengthMenu": "每页 _MENU_ 条记录",
             "zeroRecords": "没有找到记录",
             "info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
             "infoEmpty": "无记录",
             "infoFiltered": "(从 _MAX_ 条记录过滤)",
             "sSearch":"搜索",
	          "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
           		 } 
             },
        
		//每页显示16条数据
		pageLength: 16,		
		columns: [{
			"data": "name",  
		},{
			"data":"system", 
		}, {
			"data":"form",
		}, 
		{
			"data": "ad",
		}, {
			"data": "PMBarea",
		},
		{
			"data":"id2",
			"render":function(data,type,full){
				var str='<a class="loaction" title="定位" href="javascript:ShowDetailWetlandPanel(\'' +data+'\')"><i class="icon icon-pushpin bigger-130"></i></a>';
				if(!Boolean(authorityArr[3])){    
					str+='<a class="update disabled" title="修改" href="javascript:editinfo(\''+data + '\')"><i class="icon icon-pencil bigger-130"></i></a>'
				}else{
					str+='<a class="update" title="修改" href="javascript:editinfo(\''+data + '\')"><i class="icon icon-pencil bigger-130"></i></a>'
				}
				
				if(!Boolean(authorityArr[1])){
					str+='<a class="delete disabled" title="删除" href="javascript:deleteinfo(\'' +data+'\',\''+full.name+'\')"><i class="icon icon-trash bigger-130"></i></a>';
				}else{
					str+='<a class="delete" title="删除" href="javascript:deleteinfo(\'' +data+'\',\''+full.name+'\')"><i class="icon icon-trash bigger-130"></i></a>';
				}
				
				return str
		}},
		],
	
	});		
	//锁定操作按钮
	if(view==false){
		$(".view").attr("disabled", true);
	}
	if(delete1==false){
		$(".delete").attr("disabled", true);
	}
	if(update==false){
		$(".update").attr("disabled", true);
	}
	mapfirstinit();
	 
});

//添加操作
function add() {
	var option = {
		dataType : 'json',
		success : function(value) {
			$('#addform').resetForm();// 重置表单
			$('#addmodal').modal('hide');
			if (value.code!=5000) {

				  new $.zui.Messager('湿地公园基本信息添加成功。', {
				        icon: 'bell', // 定义消息图标
       		        	type:'info' 
				    }).show();
				window.location.href='../wetlandManager/indexnew?id='+value.id;
			} else {

				  new $.zui.Messager('湿地公园基本信息添加失败。', {
				        icon: 'bell', // 定义消息图标
       		        	type:'danger' 
				    }).show();
			}
		},
			error : function() {

				  new $.zui.Messager('服务器报错，请联系相关人员。', {
				        icon: 'bell', // 定义消息图标
       		        	type:'danger' 
				    }).show();
				}
		};
	$("#addform").ajaxForm(option).submit();
	}

			
function search() {
	var name = $("#search").val();
	$.ajax({
		url : "findbyname",
		dataType : "json",
		type : "POST",
		data : {
			name : name
		},
		async : true,

		success : function(strValue) {
			if (strValue.length != 0) {
				mapinit(strValue);
			}
		}
	});
}

function getAllWetland() {
	
	$.ajax({
		url : "../wetlandManager/all",
		dataType : "json",
		type : "POST",
		data : {},
		async :true,
		error : function(error) {
			console.log(error.responseText);


			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell', // 定义消息图标
   		        	type:'danger' 
			    }).show();
		},
		success : function(strValue) {
			if (strValue != null) {
				ShowWetlandOnMap(strValue);
			}
		}
	});
}

function confirm() {
	var prov = $("#province").val();
	var city = $("#selectcity").val();
	var dist = $("#selectdist").val();
	var system = $("#search_system").val();
	var name = $("#search").val();
	var form = $("#search_form").val()
	$.ajax({
		url : "../wetlandManager/findbysearchnew",
		dataType : "json",
		type : "POST",
		data : {
			prov : prov,
			city : city,
			dist : dist,
			system : system,
			name : name,
			form : form,
			type:'湿地'
		},
		async : true,
		error : function(error) {
			console.log(error.responseText);


			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell', // 定义消息图标
   		        	type:'danger' 
			    }).show();
		},
		success : function(strValue) {
			//alert(strValue.length);
			if (strValue.length!= 0) {
				ShowWetlandOnMap(strValue);
			}
			else {
				plainmap();
				}
		}
	});
}

function mapfirstinit(){
	$("#map").empty();
	$("#toc").empty();
	dojo.require("esri.map");

	$.ajax({
		url : "../wetlandManager/calculatecenterandscale",
		dataType : "json",
		type : "POST",
		data : {},
		async : true,
		error : function(error) {
			console.log(error.responseText);


			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell', // 定义消息图标
   		        	type:'danger' 
			    }).show();
		},
		success : function(strValue) {
			//alert(strValue.length);
			if (strValue != null) {
				ShowWetlandOnMapFirst(strValue);
			}

		}
	});
	
}

function plainmap() {
	$("#map").empty();
	$("#toc").empty();
	var graphicLayer;
	var longitudesum = 0;
	var latitudesum = 0;
	require([ "esri/map", "esri/geometry/Circle",
			"esri/symbols/SimpleFillSymbol", "esri/graphic",
			"esri/layers/GraphicsLayer", "dojo/dom", "dojo/dom-attr",
			"dojo/domReady!" ], function(Map, Circle, SimpleFillSymbol,
			Grahpic, GraphicsLayer, dom, domAttr) {
		map = new Map("map", {
			basemap : "streets",
			slider : true,
			zoom : 4
		});
		
		//var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer");
        //map.addLayer(basemap);
		var point =new esri.geometry.Point(107.2472950000,
				33.2466840000, map.spatialReference);
		map.centerAt(point);
		map.showZoomSlider();
	});
}



function mapinit(wetland) {
	$("#map").empty();
	$("#toc").empty();
	dojo.require("esri.map");

	var layer, visible = [];
	function init() {
		map = new esri.Map("map");
		//var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer");
       // map.addLayer(basemap);
		map.setBasemap("streets");
		var point = new esri.geometry.Point(wetland.wlin_longitude,
				wetland.wlin_latitude);
		map.centerAndZoom(point, 12);
		// clearMap();
		layer = new esri.layers.ArcGISDynamicMapServiceLayer(wetland.wlin_gis_mapserver_url);
		//layer.attr("longitude",wetland.wlin_longitude+10);
		// layer.visible = false;
		if (layer.loaded) {
			buildLayerList(layer);
		} else {
			dojo.connect(layer, "onLoad", buildLayerList);
		}
//		dojo.connect(map, "onMouseMove", showCoordinates);
	}

	function getChildrenNodes(parentnodes, node) {
		for (var i = parentnodes.length - 1; i >= 0; i--) {

			var pnode = parentnodes[i];
			// 如果是父子关系，为父节点增加子节点，退出for循环
			if (pnode.id == node.pid) {
				pnode.state = "closed";// 关闭二级树
				pnode.children.push(node);
				return;
			} else {
				// 如果不是父子关系，删除父节点栈里当前的节点，
				// 继续此次循环，直到确定父子关系或不存在退出for循环
				parentnodes.pop();
			}
		}
	}

	function buildLayerList(layer) {
		var layerinfos = layer.layerInfos;
		var treeList = [];// jquery-easyui的tree用到的tree_data.json数组
		var parentnodes = [];// 保存所有的父亲节点
		var root = {
			"id" : "rootnode",
			"text" : "所有图层",
			"children" : []
		};// 增加一个根节点
		var node = {};
		if (layerinfos != null && layerinfos.length > 0) {

			for (var i = 0, j = layerinfos.length; i < j; i++) {
				var info = layerinfos[i];
				if (info.defaultVisibility) {
					visible.push(info.id);
				}

				node = {
					"id" : info.id,
					"text" : info.name,
					"pid" : info.parentLayerId,
					"checked" : info.defaultVisibility ? true : false,
					"children" : []
				};
				if (info.parentLayerId == -1) {
					parentnodes.push(node);
					root.children.push(node);
				} else {
					getChildrenNodes(parentnodes, node);
					parentnodes.push(node);
				}
			}
		}
		treeList.push(root);
		// jquery-easyui的树
		$('#toc').tree({
			data : treeList,
			checkbox : true, // 使节点增加选择框
			onCheck : function(node, checked) {// 更新显示选择的图层
				var visible = [];

				var nodes = $('#toc').tree("getChecked");
				dojo.forEach(nodes, function(node) {
					visible.push(node.id);
				});
				// if there aren't any layers visible set the array to be -1
				if (visible.length == 0) {
					visible.push(-1);
				}
				layer.setVisibleLayers(visible);
			}
		});

		layer.setVisibleLayers(visible);
		map.addLayer(layer);

	}

	dojo.ready(init);
}

function ShowWetlandOnMapFirst(wetlands) {
	$("#map").empty();
	$("#toc").empty();
	
	var graphicLayer;
	var longitudesum = 0;
	var latitudesum = 0;

	require([ "esri/map", "esri/geometry/Circle",
			"esri/symbols/SimpleFillSymbol", "esri/graphic",
			"esri/layers/GraphicsLayer", "dojo/dom", "dojo/dom-attr",
			"dojo/domReady!" ], function(Map, Circle, SimpleFillSymbol,
			Grahpic, GraphicsLayer, dom, domAttr) {
		map = new Map("map", {
			basemap : "streets",
			// center: [wetlands[0].wlin_coordinates.longitude,
			// wetlands[0].wlin_coordinates.latitude],
			slider : true,
			zoom : wetlands[wetlands.length-1].wlin_scale
		});
		//var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer");
       // map.addLayer(basemap);
		//创建图层
		graphicLayer = new GraphicsLayer();
		// 把图层添加到地图上
		map.addLayer(graphicLayer);
		
		
		for(var i=0;i<wetlands.length-1;i++){
			addMarker(wetlands[i].wlin_longitude,
					wetlands[i].wlin_latitude, wetlands[i]);
			//map.infoWindow.resize(200, 200);
			//mapAddOverLay(wetlands[i].wlin_longitude, wetlands[i].wlin_latitude, wetlands[i].id, wetlands[i].wlin_name);
		}

		var point =new esri.geometry.Point(wetlands[wetlands.length-1].wlin_longitude,
				wetlands[wetlands.length-1].wlin_latitude, map.spatialReference);
		map.centerAt(point);

		map.showZoomSlider();

	});

	

	function addMarker(xx, yy, value) {

		// 设置标注的经纬度
		// 方法一
		var pt = new esri.geometry.Point(xx, yy, map.spatialReference);
		// 方法二
		// var pt = new esri.geometry.geographicToWebMercator(new
		// esri.geometry.Point({
		// "x": 118.0605760000,
		// "y": 36.8424320000,
		// "spatialReference": { "wkid": 102113 }
		// }));

		// 设置标注显示的图标
		// var symbol1 = new esri.symbol.SimpleMarkerSymbol();
		var symbol1 = new esri.symbol.PictureMarkerSymbol(
				"../assets/images/green3.png", 25, 25);
		//var symbol2 =  new esri.symbol.TextSymbol(value.wlin_name);
		

		


		// 要在模版中显示的参数
		var attr = {
			"wetlandName" : value.wlin_name,
			"wetlandad" : value.wlin_province + value.wlin_city + value.wlin_district,
			"wetlandArea" : value.wlin_official_area,
			"wetlandProtection" : value.wlin_protection_level,
			"wetlandManagementName" : value.wlin_management_name
		};

		// 创建模版
		var infoTemplate = new esri.InfoTemplate();
		infoTemplate.setTitle("${wetlandName}");
        infoTemplate.setContent(
        		"湿地名称: ${wetlandName}<br/>" +
        		"行政区划: ${wetlandad}  <br/>" +
        		"湿地面积: ${wetlandArea}公顷  <br/>" +
        		"保护体系: ${wetlandProtection}  <br/>" +
        		"管理单位: ${wetlandManagementName}  <br/>" +
        		"<div><a href='javascript:ShowDetailWetlandPanel(\""
				+ value.id + "\")'>查看详情</a> </div>");

		// 创建图像
		var graphic1 = new esri.Graphic(pt, symbol1, attr, infoTemplate);
		
		// 把图像添加到刚才创建的图层上
		graphicLayer.add(graphic1);
		
	}

	function setMapCenter(xx, yy, level) {
		var point = new esri.geometry.Point(xx, yy, map.spatialReference);
		map.centerAndZoom(point, level);
	}

	
}

function ShowWetlandOnMap(wetlands) {
	$("#map").empty();
	$("#toc").empty();
	
	var graphicLayer;
	var longitudesum = 0;
	var latitudesum = 0;

	require([ "esri/map", "esri/geometry/Circle",
			"esri/symbols/SimpleFillSymbol", "esri/graphic",
			"esri/layers/GraphicsLayer", "dojo/dom", "dojo/dom-attr",
			"dojo/domReady!" ], function(Map, Circle, SimpleFillSymbol,
			Grahpic, GraphicsLayer, dom, domAttr) {
		map = new Map("map", {
			basemap : "streets",
			// center: [wetlands[0].wlin_coordinates.longitude,
			// wetlands[0].wlin_coordinates.latitude],
			slider : true,
			zoom : wetlands[wetlands.length-1].wlin_scale
		});
		//var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer");
       // map.addLayer(basemap);
		// 创建图层
		graphicLayer = new GraphicsLayer();
		// 把图层添加到地图上
		map.addLayer(graphicLayer);
		
		
		for(var i=0;i<wetlands.length-1;i++){
			addMarker(wetlands[i].wlin_longitude,
					wetlands[i].wlin_latitude, wetlands[i]);
			//map.infoWindow.resize(200, 200);
			//mapAddOverLay(wetlands[i].wlin_longitude, wetlands[i].wlin_latitude, wetlands[i].id, wetlands[i].wlin_name);
		}

		var point =new esri.geometry.Point(wetlands[wetlands.length-1].wlin_longitude,
				wetlands[wetlands.length-1].wlin_latitude, map.spatialReference);
		map.centerAt(point);

		map.showZoomSlider();

	});

	

	function addMarker(xx, yy, value) {

		// 设置标注的经纬度
		// 方法一
		var pt = new esri.geometry.Point(xx, yy, map.spatialReference);
		// 方法二
		// var pt = new esri.geometry.geographicToWebMercator(new
		// esri.geometry.Point({
		// "x": 118.0605760000,
		// "y": 36.8424320000,
		// "spatialReference": { "wkid": 102113 }
		// }));

		// 设置标注显示的图标
		// var symbol1 = new esri.symbol.SimpleMarkerSymbol();
		var symbol1 = new esri.symbol.PictureMarkerSymbol(
				"../assets/images/green3.png", 25, 25);
		//var symbol2 =  new esri.symbol.TextSymbol(value.wlin_name);
		var symbol2 = new esri.symbol.TextSymbol({
			  color: "white",
			  haloColor: "black",
			  haloSize: "1px",
			  text: value.wlin_name,
			  xoffset: 10,
			  yoffset: 10,
			//  type:"picturemarkersymbol",
				
			  font: {  // autocast as esri/symbols/Font
			    size: 8,
			    family: "sans-serif"
			   
			  }
			});

		


		// 要在模版中显示的参数
		var attr = {
			"wetlandName" : value.wlin_name,
			"wetlandad" : value.wlin_province + value.wlin_city + value.wlin_district,
			"wetlandArea" : value.wlin_official_area,
			"wetlandProtection" : value.wlin_protection_level,
			"wetlandManagementName" : value.wlin_management_name
		};

		// 创建模版
		var infoTemplate = new esri.InfoTemplate();
		infoTemplate.setTitle("${wetlandName}");
        infoTemplate.setContent(
        		"湿地名称: ${wetlandName}<br/>" +
        		"行政区划: ${wetlandad}  <br/>" +
        		"湿地面积: ${wetlandArea}公顷  <br/>" +
        		"保护体系: ${wetlandProtection}  <br/>" +
        		"管理单位: ${wetlandManagementName}  <br/>" +
        		"<div><a href='javascript:ShowDetailWetlandPanel(\""
				+ value.id + "\")'>查看详情</a> </div>");

		// 创建图像
		var graphic1 = new esri.Graphic(pt, symbol1, attr, infoTemplate);
		var graphic2 = new esri.Graphic(pt, symbol2, attr, infoTemplate);
		// 把图像添加到刚才创建的图层上
		graphicLayer.add(graphic1);
		graphicLayer.add(graphic2);
	}

	function setMapCenter(xx, yy, level) {
		var point = new esri.geometry.Point(xx, yy, map.spatialReference);
		map.centerAndZoom(point, level);
	}

	
}
function ShowDetailWetlandPanel(id) {
	$.ajax({
		url : "../wetlandManager/findbyid",
		dataType : "json",
		type : "POST",
		data : {
			id : id
		},
		async : true,
		error : function(error) {
			console.log(error.responseText);


			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell', // 定义消息图标
   		        	type:'danger' 
			    }).show();

		},
		success : function(strValue) {
			if (strValue != null) {

				// 动态添加点到arcgis图中的代码，strValue为WetlandEntity

				mapinit(strValue);

			}
		}
	});
}


function ShowDetailWetlandPanelByName(name) {
	$.ajax({
		url : "../wetlandManager/findbyname",
		dataType : "json",
		type : "POST",
		data : {
			name : name
		},
		async :true,
		error : function(error) {
			console.log(error.responseText);

			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell', // 定义消息图标
   		        	type:'danger' 
			    }).show();

		},
		success : function(strValue) {
			if (strValue != null) {

				// 动态添加点到arcgis图中的代码，strValue为WetlandEntity

				mapinit(strValue);

			}
		}
	});
}
//删除
function deleteinfo(id, name) {
	if (id != "") {

					$.ajax({
						url : "delete",
						dataType : "json",
						type : "POST",
						data : {
							id : id
						},
						async : false,
						error : function(error) {
							console.log(error.responseText);


							  new $.zui.Messager('服务器报错，请联系相关人员。', {
							        icon: 'bell', // 定义消息图标
			       		        	type:'danger' 
							    }).show();
						},
						success : function(strValue) {

							if (strValue == 1) {


								  new $.zui.Messager('湿地公园删除成功。', {
								        icon: 'bell', // 定义消息图标
				       		        	type:'info' 
								    }).show();
								oTable1.ajax.reload();

							} else if (strValue == 2) {

								  new $.zui.Messager('湿地公园删除失败。', {
								        icon: 'bell', // 定义消息图标
				       		        	type:'danger' 
								    }).show();
							} else if (strValue == 3) {
		
								  new $.zui.Messager('请先在监测站点解除绑定。', {
								        icon: 'bell', // 定义消息图标
				       		        	type:'danger' 
								    }).show();
							}

						}
					});
	}

}
//启动编辑
function editinfo(id) {

			window.location.href='../wetlandManager/indexnew?id='+id;
			

}


	

function selectwetland(){
	var name = $('#select').val().split('_')[0];
	ShowDetailWetlandPanelByName(name);
}


function uploadexcel() {

	var option = {
		dataType : 'json',

		success : function(value) {
		
			$('#myModal2').modal('hide');
			if (value == true) {

				  new $.zui.Messager('导入保护主体数据成功。', {
				        icon: 'bell', // 定义消息图标
       		        	type:'info' 
				    }).show();
				$('#sample-table-2').DataTable().ajax.reload();
			} else {
				  new $.zui.Messager('导入保护主体数据失败。', {
				        icon: 'bell', // 定义消息图标
       		        	type:'danger' 
				    }).show();
			}
		},
		error : function() {

			  new $.zui.Messager('服务器报错，请联系相关人员。', {
			        icon: 'bell', // 定义消息图标
   		        	type:'danger' 
			    }).show();
			
		}
	};
	$("#uploadxlsform").ajaxForm(option).submit();
}

//添加validation验证规则
function addWetlandFormValidate() {
	validator = $('#addform').validate({
		errorElement : 'div',
		errorClass : 'help-block',
		focusInvalid : false,
		rules : {
			name : {
				required : true,
				minlength : 2,
				maxlength : 30,
				remote : {
					url : "../wetlandManager/checkname", // 后台处理程序
					type : "post", // 数据发送方式
					
					dataType : "json", // 接受数据格式
					data : { // 要传递的数据
						name : function() {
							return $('#name').val();
						}
					}
				}
			},
			addcity:{
				required : true
			}
		},

		messages : {
			name : {
				required : "<div class='col-xs-1'></div>请输入保护主体名称！",
				minlength : "<div class='col-xs-1'></div>最小长度不能小于2个字符！",
				maxlength : "<div class='col-xs-1'></div>最大长度不能大于30个字符！",
				remote : "<div class='col-xs-1'></div>系统中已经存在此姓名，请勿重复！"
			},
			addcity:{
				required : "<div class='col-xs-1'></div>请选择城市（区）！"
			}

		},
		onkeyup : false,
		focusCleanup : true,
		highlight : function(e) {
			$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
		},

		success : function(e) {
			$(e).closest('.form-group').removeClass('has-error').addClass('has-info');
			//$(e).remove();
		}
	}); 
}

	

